package com.freecloud.plug.kafka.interceptor;

import org.apache.kafka.clients.producer.*;

import java.util.Map;


/**
 * @Author: maomao
 * @Date: 2021-02-21 16:09
 */
public class CustomInterceptor implements ProducerInterceptor<String, String> {
    // 发送消息时触发
    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        System.out.println("发送消息时触发");
        return record;
    }

    // 收到服务端的ACK时触发
    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
        System.out.println("消息被服务端接收");
    }

    @Override
    public void close() {
        System.out.println("生产者关闭");
    }

    // 用键值对配置时触发
    @Override
    public void configure(Map<String, ?> configs) {
        System.out.println("configure...");
    }
}
